package com.jackykeke.kdatabasedemo.db.dao

import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import android.util.Log
import com.jackykeke.kdatabasedemo.db.helper.BaseDatabaseHelper
import com.jackykeke.kdatabasedemo.db.table.GameLibTable

class GameDao {


    private var mDBHelper: BaseDatabaseHelper? = null

    constructor(mDBHelper: BaseDatabaseHelper) {
        this.mDBHelper = mDBHelper
    }


    fun isNum5Game() {
        var cursor: Cursor? = null



        try {
            Log.d("GameDao", "query start")
            cursor= mDBHelper?.query(
                GameLibTable.TABLE_NAME,
                null,
                GameLibTable.PACKAGE_NAME_ID + " LIKE ?",
                arrayOf("5%"),
                null
            )




            Log.d("GameDao", "query end")

            cursor?.let {
                Log.d("GameDao", "let start")

                if (cursor.moveToFirst()) {
                    Log.d("GameDao", "do")

                    do {
                        val packageNameId =
                            cursor.getString(cursor.getColumnIndex(GameLibTable.PACKAGE_NAME_ID))
                        Log.d("GameDao", "packageNameId:$packageNameId")

                    } while (cursor.moveToNext())
                }

            }
        } catch (e: Exception) {
            Log.d("GameDao", "失误了 ${e.printStackTrace()}")
        } finally {
            Log.d("GameDao", " finally")
            cursor?.close()
        }


    }
}